<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta name="keywords" content="hexo, autumn" />
    <title>
        iOS开发
    </title>
    <!-- favicon -->
    
    <link rel="icon" href="https://cdn.jsdelivr.net/gh/frontendsophie/hexo-theme-autumn@1.0.0/source/img/favicon.ico" />
     <link rel="stylesheet" href="/blog/css/style.css">

    <!-- highlight -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/github-gist.min.css" />
    <script src="//cdn.bootcss.com/highlight.js/9.2.0/highlight.min.js"></script>
    <script>
        hljs.initHighlightingOnLoad()
    </script>
    <script src="https://cdn.jsdelivr.net/gh/frontendsophie/hexo-infinite-scroll@2.0.0/dist/main.js"></script>

    <script>
        infiniteScroll()

        window.addEventListener('DOMContentLoaded', function () {
            const [
                mainTitle,
                mobileMenu,
                mobileMainTitle,
                mobileMenuBtn,
                ipadMenuBtn,
                aside,
                closeBtn,
            ] = getEle(
                '#main-title',
                '.mobile-menu',
                '.mobile-menu h3',
                '.mobile-menu button',
                '.ipad-menu',
                'aside',
                'aside .close',
            )
            const io = new IntersectionObserver(entries => {
                if (entries[0].intersectionRatio <= 0) {
                    mobileMainTitle.classList.remove('invisibile')
                } else {
                    mobileMainTitle.classList.add('invisibile')
                }
            })
            io.observe(mainTitle)

            clickToggleAside(mobileMenuBtn)
            clickToggleAside(ipadMenuBtn)
            clickToggleAside(closeBtn, false)

            const isMenuVisible = window.getComputedStyle(mobileMenu).display !== 'none'
            if (isMenuVisible) document.body.style.background = 'none'

            function getEle(...args) {
                return args.map(arg => document.querySelector(arg))
            }

            function clickToggleAside(btn, show = true) {
                btn.addEventListener('click', function () {
                    if (show) {
                        aside.style.display = 'block'
                    } else {
                        aside.style.display = 'none'
                    }
                })
            }
        })
    </script>
</head>

<body style="background: url(https://cdn.jsdelivr.net/gh/frontendsophie/hexo-theme-autumn@1.0.0/source/img/button-bg.png) #f3f3f3">
    <div class="container">
        <header class="header">
    <nav class="mobile-menu" style="background: url(https://cdn.jsdelivr.net/gh/frontendsophie/hexo-theme-autumn@1.0.0/source/img/button-bg.png) #f3f3f3">
        <h3 class="invisibile">
            <a href="/blog/" class="logo">
                iOS开发
            </a>
        </h3>
        <button class="menu">menu</button>
    </nav>

    <button class="ipad-menu menu">menu</button>

    <h1 class="title" id="main-title">
        <a href="/blog/" class="logo">
            iOS开发
        </a>
    </h1>
    <h2 class="desc">
        
    </h2>

    <div class="links">
        <ul>
            
            <li>
                <a href="https://github.com/FrontendSophie" target="_blank" rel="noopener">
                    Github
                </a>
            </li>
            
            <li>
                <a href="https://www.linkedin.com/in/frontendsophie/" target="_blank" rel="noopener">
                    LinkedIn
                </a>
            </li>
            
        </ul>
    </div>
</header>
        <main class="main">
            <article class="post">
    
    
    
    <h2 class="post-title">
        iOS去除storyboard,纯代码开发(含swift)
    </h2>
    <ul class="post-date">
        <li>
            2020-02-28
        </li>
        <li>
            selinaSun
        </li>
    </ul>
    <div class="post-content">
        <h3 id="苹果公司虽然大力推荐-storyboard，但是对于多数-iOS-开发者而言还是更喜欢纯代码开发。然而我们每次创建一个新的项目的时候-项目工程中都会自带一个-storyboard。要去除这个默认-storyboard-进行纯代码开发也并非难事，只要做以下几个步骤。"><a href="#苹果公司虽然大力推荐-storyboard，但是对于多数-iOS-开发者而言还是更喜欢纯代码开发。然而我们每次创建一个新的项目的时候-项目工程中都会自带一个-storyboard。要去除这个默认-storyboard-进行纯代码开发也并非难事，只要做以下几个步骤。" class="headerlink" title="苹果公司虽然大力推荐 storyboard，但是对于多数 iOS 开发者而言还是更喜欢纯代码开发。然而我们每次创建一个新的项目的时候,项目工程中都会自带一个 storyboard。要去除这个默认 storyboard 进行纯代码开发也并非难事，只要做以下几个步骤。"></a>苹果公司虽然大力推荐 storyboard，但是对于多数 iOS 开发者而言还是更喜欢纯代码开发。然而我们每次创建一个新的项目的时候,项目工程中都会自带一个 storyboard。要去除这个默认 storyboard 进行纯代码开发也并非难事，只要做以下几个步骤。</h3><h3 id="1-删除项目设置中的-Main-interface"><a href="#1-删除项目设置中的-Main-interface" class="headerlink" title="1.删除项目设置中的 Main interface"></a>1.删除项目设置中的 Main interface</h3><p><img src="https://gitee.com/selinaSun/blog_Img/raw/master/IMG/20200228142129/637119-ab382a95fb1676ab.jpg" alt="img"></p>
<h3 id="2-删除目录文件中的-Main-storyboard"><a href="#2-删除目录文件中的-Main-storyboard" class="headerlink" title="2.删除目录文件中的 Main.storyboard"></a>2.删除目录文件中的 Main.storyboard</h3><p><img src="https://gitee.com/selinaSun/blog_Img/raw/master/IMG/20200228142129/637119-340ba978bf6b3ec4.jpg" alt="img"></p>
<h3 id="3-在AppDelegate-中添加项目的-window-并添加所需的-viewController"><a href="#3-在AppDelegate-中添加项目的-window-并添加所需的-viewController" class="headerlink" title="3.在AppDelegate 中添加项目的 window 并添加所需的 viewController"></a>3.在AppDelegate 中添加项目的 window 并添加所需的 viewController</h3><h4 id="只需在didFinishLaunchingWithOptions中添加以下方法即可"><a href="#只需在didFinishLaunchingWithOptions中添加以下方法即可" class="headerlink" title="只需在didFinishLaunchingWithOptions中添加以下方法即可"></a>只需在didFinishLaunchingWithOptions中添加以下方法即可</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions &#123;</span><br><span class="line"></span><br><span class="line">// Override point <span class="keyword">for</span> customization after application launch.</span><br><span class="line"></span><br><span class="line">self.window= [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];</span><br><span class="line"></span><br><span class="line">// show root controller.</span><br><span class="line"></span><br><span class="line">self.window.rootViewController= [[ViewController alloc] init];</span><br><span class="line"></span><br><span class="line">[self.window makeKeyAndVisible];</span><br><span class="line"></span><br><span class="line"><span class="built_in">return</span> YES;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="记得要引入对应的-viewController-头文件哟！"><a href="#记得要引入对应的-viewController-头文件哟！" class="headerlink" title="记得要引入对应的 viewController 头文件哟！"></a>记得要引入对应的 viewController 头文件哟！</h4><h3 id="SWIFT-代码如下"><a href="#SWIFT-代码如下" class="headerlink" title="SWIFT 代码如下"></a>SWIFT 代码如下</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool &#123;       </span><br><span class="line"></span><br><span class="line">  // Override point <span class="keyword">for</span> customization after application launch.        </span><br><span class="line"></span><br><span class="line"> window = UIWindow(frame: UIScreen.main.bounds)         </span><br><span class="line"></span><br><span class="line">window?.rootViewController = ViewController()         </span><br><span class="line"></span><br><span class="line">window?.backgroundColor = UIColor.white        </span><br><span class="line"></span><br><span class="line"> window?.makeKeyAndVisible()        </span><br><span class="line"></span><br><span class="line"> <span class="built_in">return</span> <span class="literal">true</span>    </span><br><span class="line"></span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h3 id="4-运行-App"><a href="#4-运行-App" class="headerlink" title="4.运行 App"></a>4.运行 App</h3><h4 id="运行app-之前最好能先清理生成文件夹，不让可能会出现运行失败的情况。清理生成文件夹的快捷键是-Shift-Command-Alt-K"><a href="#运行app-之前最好能先清理生成文件夹，不让可能会出现运行失败的情况。清理生成文件夹的快捷键是-Shift-Command-Alt-K" class="headerlink" title="运行app 之前最好能先清理生成文件夹，不让可能会出现运行失败的情况。清理生成文件夹的快捷键是 Shift+Command+Alt+K."></a>运行app 之前最好能先清理生成文件夹，不让可能会出现运行失败的情况。清理生成文件夹的快捷键是 Shift+Command+Alt+K.</h4><p><img src="https://gitee.com/selinaSun/blog_Img/raw/master/IMG/20200228142129/637119-119f976994425de3.png" alt="img"></p>
<h4 id="出现这个提示框后确认-Clean-。"><a href="#出现这个提示框后确认-Clean-。" class="headerlink" title="出现这个提示框后确认 Clean 。"></a>出现这个提示框后确认 Clean 。</h4>
    </div>
</article>
        </main>
        <aside class="aside">
            <div class="close"></div>
            <section class="aside-section">
                
    <h1>Categories</h1>

    

            </section>
            <section class="aside-section">
                
    <h1>Archives</h1>

    <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/">2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/">2019</a></li></ul>


            </section>
            <section class="aside-section tag">
                
    <h1>Tags</h1>

    

            </section>
        </aside>
    </div>
</body>

</html>